<template>
	<view class="chatitem">
		<view v-if="isLeft" class="leftitem">
			<image class="icon" :src="icon"></image>
			<view class="info">
				<text class="nickname">{{ nickname }}</text>
				<text class="message">
					<text class="angle"></text>
					{{ message }}
				</text>
			</view>
		</view>
		<view v-else class="rightitem">
			<view class="info">
				<text class="nickname">{{ nickname }}</text>
				<text class="message">
					<text class="angle"></text>
					{{ message }}
				</text>
			</view>
			<image class="icon" :src="icon"></image>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			isLeft: {
				type: Boolean,
				default: true
			},
			nickname: {
				type: String,
				default: "默认"
			},
			message: {
				type: String,
				default: "你好呀"
			},
			icon: {
				type: String,
				default: "https://dss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1141259048,554497535&fm=26&gp=0.jpg"
			},
		},
		data() {
			return {
				
			};
		}
	}
</script>

<style lang="less" scoped>
.iconStyle() {
		display: inline-block;
		width: 80rpx;
		height: 80rpx;
		border-radius: 12rpx;
	}
	.chatitem {
		// width: 100%;
		background-color: #f2f2f2;
		padding: 30rpx 0;
		.leftitem {
			display: flex;
			position: relative;
			.icon {
				.iconStyle;
					position: absolute;
					left: 20rpx;
			}
			.info {
				margin: 6rpx 20rpx;
				.nickname {
					font-size: 22rpx;
					color: #9b9b9b;
					display: block;
					position: absolute;
					left: 120rpx;
				}
				.message {
					flex: 1;
					// width: calc(100% - 240rpx);
					margin-right: 200rpx;
					display: block;	
					position: relative;
					top: 45rpx;
					left: 100rpx;
					font-size: 28rpx;
					margin-top: 6rpx;
					padding: 20rpx 20rpx;
					background-color: #fff;
					border-radius: 10rpx;
					// text-align: justify;
					
					.angle {
						position: absolute;
						left: -23rpx;
						top: 28rpx;
						width: 0;
						height: 0;
						border: 10rpx solid transparent;
						border-right: 15rpx solid #fff;
					}
				}
			}
		}
		.rightitem {
			display: flex;
			justify-content: flex-end;
			position: relative;
			.icon {
				.iconStyle;
				position: absolute;
				right: 20rpx;
			}
			.info {
				margin: 6rpx 20rpx;
				text-align: right;
				.nickname {
					font-size: 9px;
					color: #9b9b9b;
					display: block;
					position: absolute;
					right: 120rpx;
				}
				.message {
					// width: calc(100% - 240rpx);
					margin-right: 200rpx;
					display: block;
					position: relative;
					top: 45rpx;
					right: -100rpx;
					font-size: 28rpx;
					margin-top: 6rpx;
					padding: 20rpx 20rpx;
					background-color: #fff;
					border-radius: 10rpx;
					
					.angle {
						position: absolute;
						right: -23rpx;
						top: 28rpx;
						width: 0;
						height: 0;
						border: 10rpx solid transparent;
						border-left: 15rpx solid #fff;
					}
				}
			}
		}
	}
</style>
